package com.shanjupay.test.rocketmq.message;

import com.alibaba.fastjson.JSON;
import com.shanjupay.test.rocketmq.model.OrderExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * @className: ConsumerSimple
 * @Description: TODO
 * @author: Huangjianyun
 * @date: 2021/10/26 14:59
 */

/*
* 添加RocketMQMessageListener注解，监听消息，里面设置my-topic主体，从nameServer中拉取my-topic对应broker消息队列
*
* */
@Component
@RocketMQMessageListener(topic = "my-topic",consumerGroup = "demo-consumer-group")
public class ConsumerSimple  implements RocketMQListener<String> {


    /*
    * 监听消息，执行该onMessage方法去消费消息，onMessage方法执行消费消息的逻辑
    *
    *
    * */
    @Override
    public void onMessage(String s) {
        //消费方式： 打印 my-topic主体下消息体
        System.out.println(s);
    }
    //自定义消息格式，被消费者消费两种方式，
    //步骤监听my-topic-obj主题从nameserver中获取对应broker的该主题下的所有对列的里面存放json消息
    //监听队列消费消息 监听的json串


//    @Override
//    public void onMessage(String s) {
//        OrderExt orderExt = JSON.parseObject(s, OrderExt.class);
//        System.out.println(s);
//        System.out.println(orderExt.getMoney());
//    }
}
